package com.jrx.anytxn.param.job.bactchBillCompare.step;

import com.jrx.anytxn.param.config.BillCompareConfig;
import com.jrx.anytxn.param.constant.Constant;
import com.jrx.anytxn.param.entity.PrOrganizationTable;
import com.jrx.anytxn.param.mapper.ext.ExtTlBillTransCompareDetailMapper;
import com.jrx.anytxn.param.service.system.IOrganizationTableService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.Objects;

@Service
public class ThirdDetailUnmatchedListener implements JobExecutionListener {
    private static final Logger logger = LoggerFactory.getLogger(ThirdDetailUnmatchedListener.class);

    @Autowired
    private IOrganizationTableService organizationTableService;
    @Resource
    private ExtTlBillTransCompareDetailMapper extTlBillTransCompareDetailMapper;

    @Autowired
    private BillCompareConfig billCompareConfig;
    @Override
    public void beforeJob(JobExecution jobExecution) {
        PrOrganizationTable org = organizationTableService.findByOrgIdForBatch(Constant.XIB_ORG_NUMBER);
        // 设置指定对账日期
        Date today = billCompareConfig.getToday();
        if (Objects.nonNull(today)) {
            org.setToday(today);
        }
        //删除当日明细对比数据，支持重跑
        extTlBillTransCompareDetailMapper.deleteUmMatchRecordByBusDateAndThirdChannel(org.getToday(),billCompareConfig.getThirdChannel());
    }

    @Override
    public void afterJob(JobExecution jobExecution) {

    }
}
